var SlotChangeData = cc.Class({
    name:'geoSlotChangeData',
    properties:{
        slotName: 'name',
        displayIndex: -1,
    }
});

/**
 * 对龙骨的插槽中的图片进行显示操作
 */
var DragonChangeSkin = cc.Class({
    extends: cc.Component,

    properties: {
        armatureDisplay:{
            default: null,
            type:dragonBones.ArmatureDisplay
        },
        changeDatas:{
            default:[],
            type:[SlotChangeData],
        },
        changeOnLoad: false
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        if (this.changeOnLoad == true)
            this.doChange();
    },

    doChange(){
        this.changeDatas.forEach((e => {
            var slot = this.armatureDisplay.armature().getSlot(e.slotName);
            slot.displayIndex = e.displayIndex;
        }).bind(this));
    },
    /**
     * 切换指定插槽的图片显示
     * @param {string} slotName 槽名称
     * @param {int} displayIndex 槽内图片索引值
     */
    changeSlotDisplay(slotName, displayIndex){
        var slot = this.armatureDisplay.armature().getSlot(slotName);
        // if (slot && displayIndex < slot.displayList.length && displayIndex >= 0)
        // slot.displayIndex = displayIndex;
        this._changeSlotDisplay(slot, displayIndex);
    },
    _changeSlotDisplay(slot, displayIndex) {
        slot.displayIndex = displayIndex;
    }

    // update (dt) {},
});

module.exports = DragonChangeSkin;
